package initdb

import (
	"fmt"
	baseLog "gitee.com/zaiqiang231/go-base-app/base_app/log"
	"gitee.com/zaiqiang231/lovesport-user-service/app/model"
	"gitee.com/zaiqiang231/lovesport-user-service/app/store"
)

type initSysDictionary struct {
	DbTable
}

func (i initSysDictionary) GetTable() store.DbTable {
	return model.SysDictionary{}
}

func (i initSysDictionary) InitData(ds *store.Datastore) {
	True := true
	var err error
	for i := 0; i < 23; i++ {
		entity := model.SysDictionary{
			Name:   fmt.Sprintf("%s%d", "性别", i),
			Type:   "gender",
			Status: &True,
			Desc:   "性别字典",
			SysDictionaryDetails: []model.SysDictionaryDetail{
				{Label: "男", Value: 1, Status: &True, Sort: 1},
				{Label: "女", Value: 2, Status: &True, Sort: 2},
			},
		}
		err = ds.DB.Create(&entity).Error
		if err != nil {
			baseLog.Errorf("initSysDictionary InitData Create fail, %v", err)
			return
		}
		err = ds.DB.Model(&entity).Association("SysDictionaryDetails").Replace(entity.SysDictionaryDetails)
		if err != nil {
			baseLog.Errorf("initSysDictionary InitData Create fail, %v", err)
			return
		}
	}
	if err != nil {
		baseLog.Errorf("initSysDictionary InitData Create fail, %v", err)
		return
	}
}
